import { IPSApplication } from '../ipsapplication';
import { IPSAppMsgTempl } from '../msg/ipsapp-msg-templ';
import { IPSAppViewMsg } from './ipsapp-view-msg';
import { IPSLanguageRes } from '../../res/ipslanguage-res';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSAppViewMsgImpl extends PSModelObjectImpl implements IPSAppViewMsg {
  get codeName(): string {
    return this.M.codeName;
  }

  protected contentpslanguageres: IPSLanguageRes | null = null;

  getContentPSLanguageRes(): IPSLanguageRes | null {
    if (this.contentpslanguageres != null) return this.contentpslanguageres;
    const value = this.M.getContentPSLanguageRes;
    if (value == null) {
      return null;
    }
    this.contentpslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getContentPSLanguageRes') as IPSLanguageRes;
    return this.contentpslanguageres;
  }

  get contentPSLanguageRes(): IPSLanguageRes | null {
    return this.getContentPSLanguageRes();
  }

  getContentPSLanguageResMust(): IPSLanguageRes {
    const value = this.getContentPSLanguageRes();
    if (value == null) {
      throw new Error('未指定内容多语言资源对象');
    }
    return value;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get dynamicMode(): 1 | 0 {
    return this.M.dynamicMode != null ? this.M.dynamicMode : 0;
  }

  get memo(): string {
    return this.M.memo;
  }

  get message(): string {
    return this.M.message;
  }

  get messageType(): 'INFO' | 'WARN' | 'ERROR' | 'CUSTOM' {
    return this.M.messageType;
  }

  get name(): string {
    return this.M.name;
  }

  get orderValue(): number {
    return this.M.orderValue != null ? this.M.orderValue : 99999;
  }

  protected psappmsgtempl: IPSAppMsgTempl | null = null;

  getPSAppMsgTempl(): IPSAppMsgTempl | null {
    if (this.psappmsgtempl != null) return this.psappmsgtempl;
    const value = this.M.getPSAppMsgTempl;
    if (value == null) {
      return null;
    }
    const ipsapplication = this.getParentPSModelObject('app.IPSApplication') as IPSApplication;
    if (ipsapplication != null) {
      this.psappmsgtempl = ipsapplication.findPSAppMsgTempl(value);
    }
    return this.psappmsgtempl;
  }

  get psAppMsgTempl(): IPSAppMsgTempl | null {
    return this.getPSAppMsgTempl();
  }

  getPSAppMsgTemplMust(): IPSAppMsgTempl {
    const value = this.getPSAppMsgTempl();
    if (value == null) {
      throw new Error('未指定应用消息模板');
    }
    return value;
  }

  get position(): 'TOP' | 'BOTTOM' | 'BODY' | 'POPUP' | 'CUSTOM' {
    return this.M.position;
  }

  get removeMode(): 0 | 1 | 2 {
    return this.M.removeMode;
  }

  get title(): string {
    return this.M.title;
  }

  get titleLanResTag(): string {
    return this.M.titleLanResTag;
  }

  protected titlepslanguageres: IPSLanguageRes | null = null;

  getTitlePSLanguageRes(): IPSLanguageRes | null {
    if (this.titlepslanguageres != null) return this.titlepslanguageres;
    const value = this.M.getTitlePSLanguageRes;
    if (value == null) {
      return null;
    }
    this.titlepslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getTitlePSLanguageRes') as IPSLanguageRes;
    return this.titlepslanguageres;
  }

  get titlePSLanguageRes(): IPSLanguageRes | null {
    return this.getTitlePSLanguageRes();
  }

  getTitlePSLanguageResMust(): IPSLanguageRes {
    const value = this.getTitlePSLanguageRes();
    if (value == null) {
      throw new Error('未指定抬头语言资源对象');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get enableRemove(): boolean {
    return this.M.enableRemove;
  }

  get cls(): string {
    return 'PSAppViewMsgImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelSortable' || cls == 'app.view.IPSAppViewMsg' || cls == 'view.IPSViewMsg') return true;
    return super.instanceof(cls);
  }
}
